import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
    history: createWebHashHistory(),
    // history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: "/",
            components: {
                view: () => import("../views/gal/index/index.vue"),
            },
            meta: { keepAlive: true }
        },
        {
            path: "/gal/index",
            components: {
                view: () => import("../views/gal/index/index.vue"),
            },
            meta: { keepAlive: true }
        },
        {
            path: "/gal/info",
            components: {
                view: () => import("../views/gal/info/index.vue"),
            },
            meta: { keepAlive: true }
        },
        {
            path: "/novel/index",
            components: {
                view: () => import("../views/novel/index/index.vue"),
            },
            meta: { keepAlive: true }
        },
        {
            path: "/novel/info",
            components: {
                view: () => import("../views/novel/info/index.vue"),
            },
            meta: { keepAlive: true }
        },
        {
            path: "/message/index",
            components: {
                view: () => import("../views/message/index/index.vue"),
            },
            meta: { keepAlive: false }
        },
    ],
});

const cachaPage = ['gal', 'novel'];

router.beforeEach((_to, _from, next) => {
    //同页面缓存
    let curPath = _to.path.split('/')[1];
    if (curPath == '')
        curPath = 'gal';
    if (cachaPage.find(u => u == curPath)) {
        window.pageCache.value = [curPath];
    } else {
        window.pageCache.value = [];
    }

    next();
});



export default router;
